|
|
@@ -77,28 +77,36 @@ def fix_user_coupon_info():
|
77
|
77
|
level_coupon = coupons.get('level{}'.format(user.level))
|
78
|
78
|
for coupon_id, coupon_num in level_coupon.items():
|
79
|
79
|
real_coupon_num = UserCouponInfo.objects.filter(user_id=user.user_id, coupon_id=coupon_id).count()
|
80
|
|
- if real_coupon_num >= coupon_num:
|
|
80
|
+ if real_coupon_num == coupon_num:
|
81
|
81
|
continue
|
82
|
82
|
|
83
|
83
|
print(user.user_id, coupon_id, coupon_num - real_coupon_num)
|
84
|
84
|
|
85
|
|
- try:
|
86
|
|
- coupon = CouponInfo.objects.get(coupon_id=coupon_id)
|
87
|
|
- except CouponInfo.DoesNotExist:
|
88
|
|
- continue
|
|
85
|
+ if real_coupon_num > coupon_num:
|
|
86
|
+ for _ in range(real_coupon_num - coupon_num):
|
|
87
|
+ user_coupons = UserCouponInfo.objects.filter(user_id=user.user_id, coupon_id=coupon_id).order_by('-pk')
|
|
88
|
+ user_coupon = user_coupons[0]
|
|
89
|
+ user_coupon.status = 0
|
|
90
|
+ user_coupon.save()
|
|
91
|
+
|
|
92
|
+ else:
|
|
93
|
+ try:
|
|
94
|
+ coupon = CouponInfo.objects.get(coupon_id=coupon_id)
|
|
95
|
+ except CouponInfo.DoesNotExist:
|
|
96
|
+ continue
|
89
|
97
|
|
90
|
|
- for _ in range(coupon_num - real_coupon_num):
|
91
|
|
- UserCouponInfo.objects.create(
|
92
|
|
- brand_id=coupon.brand_id,
|
93
|
|
- brand_name=coupon.brand_name,
|
94
|
|
- coupon_id=coupon_id,
|
95
|
|
- user_id=user.user_id,
|
96
|
|
- coupon_title=coupon.coupon_title,
|
97
|
|
- coupon_detail=coupon.coupon_detail,
|
98
|
|
- coupon_value=coupon.coupon_value,
|
99
|
|
- coupon_image=coupon.coupon_image,
|
100
|
|
- active_at=tc.utc_datetime(),
|
101
|
|
- expire_at=tc.utc_datetime(days=365),
|
102
|
|
- coupon_valid_period=coupon.coupon_valid_period,
|
103
|
|
- coupon_limit_model_ids=coupon.coupon_limit_model_ids,
|
104
|
|
- )
|
|
98
|
+ for _ in range(coupon_num - real_coupon_num):
|
|
99
|
+ UserCouponInfo.objects.create(
|
|
100
|
+ brand_id=coupon.brand_id,
|
|
101
|
+ brand_name=coupon.brand_name,
|
|
102
|
+ coupon_id=coupon_id,
|
|
103
|
+ user_id=user.user_id,
|
|
104
|
+ coupon_title=coupon.coupon_title,
|
|
105
|
+ coupon_detail=coupon.coupon_detail,
|
|
106
|
+ coupon_value=coupon.coupon_value,
|
|
107
|
+ coupon_image=coupon.coupon_image,
|
|
108
|
+ active_at=tc.utc_datetime(),
|
|
109
|
+ expire_at=tc.utc_datetime(days=365),
|
|
110
|
+ coupon_valid_period=coupon.coupon_valid_period,
|
|
111
|
+ coupon_limit_model_ids=coupon.coupon_limit_model_ids,
|
|
112
|
+ )
|